﻿using System;
using System.Collections.Generic;
using Drill.Configuration;
using Drill.Extensibility;

namespace Drill.Core.MasterFactories
{
	public class ConfigBasedMasterDrillBitSetFactory : IDrillBitSetFactory
	{
		private readonly IDrillBitConfigurationCollection _configs;

		public ConfigBasedMasterDrillBitSetFactory(IDrillBitConfigurationCollection configs)
		{
			if (null == configs)
			{
				throw new ArgumentNullException("configs");
			}
			_configs = configs;
		}

		public IList<IDrillBit> CreateDrillBits(IConfigurationHelper configurationHelper)
		{
			List<IDrillBit> drillBits = new List<IDrillBit>();

			if (null != _configs && _configs.Count > 0)
			{
				foreach (var config in _configs)
				{
					if (config.Enabled)
					{
						IDrillBitFactory factory = new ConfigBasedMasterDrillBitFactory(config, configurationHelper);
						IDrillBit drillBit = factory.CreateDrillBit();
						if (null == drillBit)
						{
							continue;
						}
						drillBits.Add(drillBit);
					}
				}
			}
			return drillBits;
		}
	}
}